import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout/index2'

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/iframe',
    name: 'Iframe',
    component: () => import('@/views/common/iframe.vue'),
    hidden: true
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/show3D',
    component: () => import('@/components/JLink/file/Show3D.vue'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    meta: { title: '工作台', icon: 'workStation' },
    children: [
      {
        path: '',
        component: () => import('@/views/common/workStation'),
        name: 'WorkStation',
        meta: { title: '工作台', icon: 'workStation' }
      }
    ]
  },
  // {
  //   path: '/homePage',
  //   component: Layout,
  //   hidden: true,
  //   meta: { title: '主页', icon: 'homepage' },
  //   children: [
  //     {
  //       path: '',
  //       component: () => import('@/views/common/homePage'),
  //       name: 'HomePage',
  //       meta: { title: '', icon: 'homepage' }
  //     }
  //   ]
  // },
  {
    path: '/workStation',
    component: Layout,
    hidden: true,
    meta: { title: '工作台', icon: 'workStation' },
    children: [
      {
        path: '',
        component: () => import('@/views/common/workStation'),
        name: 'WorkStation',
        meta: { title: '工作台', icon: 'workStation' }
      }
    ]
  },
  {
    path: '/personalCenter',
    component: Layout,
    hidden: true,
    meta: { title: '个人中心', icon: 'personalCenter' },
    children: [
      {
        path: '',
        component: () => import('@/views/common/personalCenter'),
        name: 'PersonalCenter',
        meta: { title: '个人中心', icon: 'personalCenter' }
      }
    ]
  },
  {
    path: '/systemSet',
    component: Layout,
    hidden: true,
    meta: { title: '系统设置', icon: 'systemSet' },
    children: [
      {
        path: '',
        component: () => import('@/views/common/systemSet'),
        name: 'SystemSet',
        meta: { title: '系统设置', icon: 'systemSet' }
      }
    ]
  },
  {
    path: '/notification',
    component: Layout,
    hidden: true,
    meta: { title: '消息通知', icon: 'notification' },
    children: [
      {
        path: '',
        component: () => import('@/views/common/notification'),
        name: 'Notification',
        meta: { title: '消息通知', icon: 'notification' }
      }
    ]
  },
  {
    path: '/backlogTask',
    component: Layout,
    hidden: false,
    meta: { title: '待办任务', icon: 'message' },
    children: [
      {
        path: '',
        component: () => import('@/views/backlogTask/index'),
        name: 'BacklogTask',
        meta: { title: '待办任务', icon: 'message' }
      }
    ]
  },
  {
    path: '/largeScreen',
    component: () => import('@/views/system/largeScreen/index'),
    hidden: true,
    meta: { title: '大屏界面', icon: 'workStation' }
  },
  {
    path: '/postItlargeScreen',
    component: () => import('@/views/system/postItLargeScreenDetail/index'),
    hidden: true,
    meta: { title: '生产车间界面', icon: 'workStation' }
  },
  {
    path: '/largeProductionScreen',
    component: () => import('@/views/ProductionManagement/largeProductionScreen'),
    hidden: true,
    meta: { title: '生产车间界面', icon: 'workStation' }
  },

  {
    path: '/startWork',
    component: () => import('@/views/ProductionManagement/ProductionCommencement/startWork'),
    hidden: true,
    meta: { title: '生产开工详情', icon: 'workStation' }
  },
  {
    path: '/reWork',
    component: () => import('@/views/ProductionManagement/ProductionCommencement/reWork'),
    hidden: true,
    meta: { title: '生产开工详情', icon: 'workStation' }
  }
]

/**
 * asyncRoutes
 * 需要通过角色判断是否显示的菜单
 */
export const asyncRoutes = [
  { path: '*', redirect: '/404', hidden: true }
  // {
  //   path: '/homePage',
  //   component: Layout,
  //   hidden: true,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/common/homePage'),
  //       name: 'HomePage'
  //     }
  //   ]
  // }
  // {
  //   path: '/personalCenter',
  //   component: Layout,
  //   hidden: true,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/pc_center/personalSet/personalSet'),
  //       name: 'HomePage',
  //       meta: { title: 'profile' }
  //     }
  //   ]
  // }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
